package com.core.service.Impl;

import com.core.dao.GlhDao;
import com.core.domain.DTO.GlhStadiumInfoDTO;
import com.core.domain.DTO.LoginUserInfoDTO;
import com.core.domain.User;
import com.core.service.GlhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GlhServiceImpl implements GlhService {
    @Autowired
    private GlhDao glhDao;

    @Override
    public User queryUser(User user) {
        return glhDao.queryByAccountAndPassword(user);
    }

    @Override
    public LoginUserInfoDTO queryUserByAccount(LoginUserInfoDTO loginUserInfoDTO) {
        System.out.println("service done......");
        return glhDao.queryUserByAccount(loginUserInfoDTO);
    }

    @Override
    public boolean addUserByLoginUserInfoDTO(LoginUserInfoDTO loginUserInfoDTO) {
        System.out.println("service done......");
        if(queryUserByAccount(loginUserInfoDTO) == null){
            glhDao.addUserByLoginUserInfoDTO(loginUserInfoDTO.getUserAccount(), loginUserInfoDTO.getUserPassword(), loginUserInfoDTO.getAge(),Integer.parseInt(loginUserInfoDTO.getGender()), loginUserInfoDTO.getPhone(),loginUserInfoDTO.getEmail());
          //  System.out.println("service over......");
            return true;
        }else{
            return false;
        }
    }

    @Override
    public int deleteByStadiumName(String stadiumName) {
        //glhDao.deleteByStadiumName(stadiumName);
        if(glhDao.queryByStadiumname(stadiumName)!= null){
            glhDao.deleteByStadiumName_fake(stadiumName);
            return 1;
        }
        else{
            return 0;
        }

    }

    @Override
    public List<User> selectAllUsers() {
        return glhDao.selectAllUsers();
    }

    @Override
    public void deleteByAccount(String account) {
        System.out.println("111");
        glhDao.deleteByAccount(account);
        System.out.println("112221");

    }

    @Override
    public void addStadium(GlhStadiumInfoDTO glhStadiumInfoDTO) {
        System.out.println("添加service");
        glhDao.addStadium(glhStadiumInfoDTO);
        System.out.println("over");
    }
}


